package com.zhiwei.codesecurity.common.utils;

import java.util.concurrent.ThreadLocalRandom;

public class RandomNumUtil {
    private final static String[] hexDigits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d",
            "e", "f"};


    /**
     * 生成随机串
     *
     * @param length
     * @return
     */
    public static String generateRandomNum(int length) {
        StringBuilder sb = new StringBuilder();
        ThreadLocalRandom tlr = ThreadLocalRandom.current();
        for (int i = 1; i < length + 1; i++) {
            int index = tlr.nextInt(0, hexDigits.length - 1);
            sb.append(hexDigits[index]);
        }
        return sb.toString();
    }
}
